package com.yuwei.module_patrol.view

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.lib_base.path.RouterPath
import com.bw.lib_common.view.BaseMvvmActivity
import com.yuwei.module_patrol.R
import com.yuwei.module_patrol.adapter.PatrolAdapter
import com.yuwei.module_patrol.databinding.ActivityPatrolBinding
import com.yuwei.module_patrol.vm.PatrolViewModel

@Route(path = RouterPath.MODULE_PATROL_ACTIVITY)
class PatrolActivity : BaseMvvmActivity<ActivityPatrolBinding>() {
    private val vm : PatrolViewModel by lazy {
        PatrolViewModel()
    }
    private val patrolAdapter = PatrolAdapter()
    override fun initViews() {
        super.initViews()
        vm.getPatrols()
        vm.getPatrolPoints()
//        vm.getPatrolPoints()
        binding.patrolRv.adapter = patrolAdapter
        binding.patrolRv.layoutManager = LinearLayoutManager(this)
        binding.patrolBack.setOnClickListener {
            finish()
        }
        binding.patrolTopBarAdd.setOnClickListener {
            ARouter.getInstance().build(RouterPath.MODULE_EDIT_PATROL_ACTIVITY).navigation()
        }
        vm.getPatrolSuccess.observe(this){
            Log.d("TAG", "initDataPatrol: ${it[0].patrolPerson}")
            patrolAdapter.data.addAll(it)
            patrolAdapter.notifyDataSetChanged()
        }
        vm.getPointSuccess.observe(this){
            patrolAdapter.setList(it)
        }
    }
    override fun observeDataChange() {

    }

    override fun getLayoutId(): Int = R.layout.activity_patrol
}